package com.zxy.server;

import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * @author : zhangxuyuan
 * @Project: springbootrabbitmq
 * @Package com.zxy.server
 * @date Date : 2021年04月20日 18:16
 */
@Service
public class OrderServer {

    private static Integer orderId=0;

    private static Map<Integer,Integer> order = new HashMap<>();

    private static Integer HAVE_PAY=1;

    private static Integer NOT_PAY = 0;

    private static Integer EXPIRE = 2;

    @PostConstruct
    public void init()
    {
        orderId++;
        order.put(orderId,0);
    }

    public static Integer createOrder()
    {
        orderId++;
        order.put(orderId,NOT_PAY);
        return orderId;
    }

    public static void payOrder(Integer orderId)
    {
        Integer statues = order.get(orderId);
        if(NOT_PAY.equals(statues))
        {
            order.put(orderId,HAVE_PAY);
        }
    }

    public static Map<Integer,Integer> getOrders()
    {
        return order;
    }

    public static void expire(Integer orderId)
    {
        Integer status = order.get(orderId);
        if(NOT_PAY.equals(status))
        {
            order.put(orderId,EXPIRE);
        }
    }

}
